package com.wanmait.wanmarecruit.job;

import com.wanmait.wanmarecruit.entity.Notice;
import com.wanmait.wanmarecruit.service.NoticeService;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Component
public class TimeOutMessageJob {
    @Resource
    private NoticeService noticeService;

    @Scheduled(cron = "0 0 0 * * ?")//半夜0点执行
    public void delTimeOut()
    {
        Date nowDate = new Date();
        List<Notice> notices = noticeService.list();
        notices.forEach(notice -> {
            int days = (int) ((nowDate.getTime() - notice.getNoticeTime().getTime()) / (1000*3600*24));
            System.out.println(days);
            if (days>7)
            {
                noticeService.removeById(notice);
            }
        });
    }
}
